<template>
	<view class="">
		<view class="listbg" v-if="list.length != 0">
			<view class="listitem" style="padding: 30rpx;" @click="goinfo(item.id)" v-for="(item,index) in list"
				:key="index" v-if="item.evaluate_date">
				<view class="tit2">
					<view class="">
						<image src="../static/icon_279@2x.png" mode=""></image>
						<text> 预约配送时间 : {{(item.groupOrder.delivery_day || '--:--:--')}}</text>
					</view>
					<text>已完成</text>
				</view>
				<view class="houtai">后台派</view>
				<!-- 正常订单 -->
				<view class="addressbox" v-if="item.task_type == 2">
					<view class="add_l">
						<view class="qu">取</view>
						<text>|</text>
						<text>{{item.juli || '0'}}km</text>
						<text>|</text>
						<view class="">收</view>
					</view>
					<view class="add_r">
						<view class="" @click.stop="getmap(item.market.latitude,item.market.longitude)">
							<text>{{item.market.address || '菜市场地址获取失败'}}</text>
							<image src="../static/icon_280@2x.png" mode=""></image>
						</view>
						<view class="" @click.stop="getmap(item.groupOrder.latitude,item.groupOrder.longitude)">
							<text>{{item.groupOrder.user_address || '收货地址获取失败'}}</text>
							<image src="../static/icon_280@2x.png" mode=""></image>
						</view>
					</view>
				</view>
				<!-- 退换货订单 -->
				<view class="addressbox" v-if="item.task_type == 3 || item.task_type == 5">
					<view class="add_l">
						<view class="qu">取</view>
						<text>|</text>
						<text>{{item.juli || '0'}}km</text>
						<text>|</text>
						<view class="">收</view>
					</view>
					<view class="add_r">
						<view class="" @click.stop="getmap(item.groupOrder.latitude,item.groupOrder.longitude)">
							<text>{{item.groupOrder.user_address || '取货地址获取失败'}}</text>
							<image src="../static/icon_280@2x.png" mode=""></image>
						</view>
						<view class="" @click.stop="getmap(item.market.latitude,item.market.longitude)">
							<text>{{item.market.address || '菜市场地址获取失败'}}</text>
							<image src="../static/icon_280@2x.png" mode=""></image>
						</view>
					</view>
				</view>


				<!-- 物品总类大于1时 -->
				<template v-if="item.allShoppingList.length > 1">
					<view class="shopname"><text class="gray">{{item.market.mar_name || '暂无'}}</text><text
							class="gray">下单时间: {{item.groupOrder.create_time || '暂无'}}</text></view>
					<view class="goods">
						<view class="imgbg">
							<image v-for="(ele,i) in item.allShoppingList" :key="i" :src="ele" v-if="i<5"></image>
							<image class="dian" v-if="item.allShoppingList.length>=5" src="../static/icon_296@2x.png"
								mode=""></image>
						</view>
						<view class="price">
							<view class="">￥<text>{{item.groupOrder.total_price || '0'}}</text></view>
							<text>共{{item.groupOrder.total_num || '0'}}件</text>
						</view>
					</view>
				</template>
				<view style="border-top:1rpx solid #e2e2e2;border-radius: 0;" class="listitem"
					@click.stop="goinfo(item.id)" v-if="item.allShoppingList.length <= 1">
					<view class="goods goods2" style="align-items: flex-start;">
						<image :src="item.allShoppingList[0]"></image>
						<view class="one">
							<text>{{item.shoppingText[0] || '暂无'}}</text>
							<text style="margin-top: 12rpx;" class="gray">下单时间:
								{{item.groupOrder.create_time || '暂无'}}</text>
						</view>
						<view class="price price2">
							<view class="">￥<text>{{item.groupOrder.total_price || '0'}}</text></view>
							<text>共{{item.groupOrder.total_num || '0'}}件</text>
						</view>
					</view>
				</view>
				<view class="goodsbtn">
					<view @click.stop="lookComment(item)" class="">查看评论</view>
				</view>
			</view>
		</view>
		<view class="nomore" v-else>
			<image src="../static/icon_294@2x.png" mode=""></image>
			<text>暂时没有任何帮买订单</text>
			<text>去订单中心帮买</text>
			<view class="">订单中心</view>
		</view>
	</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";
	export default {
		components: {
			wPicker
		},
		data() {
			return {
				loadingType: 0, //分页
				goData: {
					status: 3,
					page: 1,
					task_date: '', //时间段
				}, //提交信息
				list: [],
				visible: false,
				date: '',
			}
		},
		onLoad(e) {},
		onShow() {
			this.goData.page = 1;
			this.loadingType = 0;
			this.list = [];
			// 获取列表
			this.getuserinfo();
		},
		//上拉加载
		onReachBottom: function() {
			if (this.loadingType == 2) {
				return uni.showToast({
					title: '没有更多了',
					icon: 'none'
				})
			}
			if (this.loadingType != 0) { //loadingType!=0;直接返回
				return false;
			}
			this.goData.page++;
			uni.showNavigationBarLoading(); //显示加载动画				
			this.getuserinfo(); //请求
		},
		methods: {
			// 查看评论
			lookComment(item) {
				let data = JSON.stringify(item);
				uni.setStorageSync('data66', data);
				uni.navigateTo({
					url: '../mine/evaluate_look'
				})
			},
			// 打开地图导航
			getmap(latitude, longitude) {
				console.log(latitude, longitude, '经纬度')
				uni.openLocation({
					latitude: latitude * 1,
					longitude: longitude * 1,
					success: function() {
						console.log('success');
					}
				});
			},
			getuserinfo() {
				this.$request('rider/task_list', {
					...this.goData
				}, 'GET').then(res => {
					console.log(res, '订单列表');
					if (res.status == 200) {
						this.list.push(...res.data.data);
						console.log(this.list, 'list');
						uni.hideNavigationBarLoading(); //关闭加载动画
						//如果长度小于等于0说明没有分页
						if (res.data.data.length < 15) {
							this.loadingType = 2; //没有更多了	
						} else {
							this.loadingType = 0; //请求成功让他返回上拉加载	
						}
						// 循环外层任务订单  
						this.list.forEach((ele, index) => {
							//不是退换货订单的情况下
							if (ele.task_type == 2|| ele.task_type == 5) {
								let shoppingList = []; //商品图片
								let shoppingText = []; //介绍
								//循环商品总订单里面的子订单
								ele.groupOrder.orderList.forEach(ele2 => {
									//商品图片
									ele2.orderProduct.forEach(ele4 => {
										// if (ele4.is_barter == 0) {
											if (ele4.cart_info.product.image) {
												shoppingList.push(
												ele4.cart_info.product.image);
												shoppingText.push(
												ele4.cart_info.product.store_name);
											}
										// }
									})

								})
								this.$set(this.list[index], 'allShoppingList', shoppingList);
								this.$set(this.list[index], 'shoppingText', shoppingText);
							}
							//上面是正常订单
							//下面是退换订单
							if (ele.task_type == 3 || ele.task_type == 4 ) {
								let shoppingList = []; //商品图片
								let shoppingText = []; //介绍
								//循环商品总订单里面的子订单
								ele.groupOrder.orderList.forEach(ele2 => {
									//商品图片
									ele2.orderProduct.forEach(ele4 => {
										if (ele4.is_barter != 0) {
											if (ele4.cart_info.product.image) {
												shoppingList.push(
												ele4.cart_info.product.image);
												shoppingText.push(
												ele4.cart_info.product.store_name);
											}
										}
									})

								})
								this.$set(this.list[index], 'allShoppingList', shoppingList);
							}
						})

						this.getDistance();
					}
				})
			},
			//经纬度算距离
			// 根据经纬度计算距离 lat1, lng1, lat2, lng2, index
			getDistance() {
				this.list.forEach(async (e, index) => {
					let a = await new Promise((resolve, reject) => {
						uni.request({
							url: `https://restapi.amap.com/v4/direction/bicycling?origin=${e.market.longitude},${e.market.latitude}&destination=${e.groupOrder.longitude},${e.groupOrder.latitude}&key=c858b6921758e3f3400070929386564c`,
						}).then((response) => {
							console.log(response[1].data.data.paths[0].distance, 'ss');
							this.$set(this.list[index], 'juli', response[1].data.data.paths[0]
								.distance * 1);
						}).catch(error => {})
					})
				})
			},
			onConfirm(e) {
				this.date = e.value[0] + ' - ' + e.value[1]
				console.log(e)
			},
			showtime() {
				this.visible = true
			},
			goinfo(id) {
				uni.navigateTo({
					url: "../order_center/orderinfo?id=" + id
				})
			},
		}
	}
</script>

<style>
	.goodsbtn .call {
		width: 160rpx;
		height: 60rpx;
		background: #FFFFFF;
		border: 1rpx solid #CCCCCC;
		border-radius: 10rpx;
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
		box-shadow: none;
		margin-right: 20rpx;
	}

	.qu {
		color: #F45E14 !important;
		background: #FFE8DC !important;
	}

	.addressbox {
		display: flex;
		width: 690rpx;
		/* margin-left: 20rpx; */
	}

	.gray {
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;
	}

	.price2>view,
	.price2>view text {
		font-size: 26rpx !important;
		font-family: Microsoft YaHei;
		font-weight: 400 !important;
		color: #333333 !important;
	}

	.price2>text {
		margin-top: 4rpx;
		font-size: 22rpx !important;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999 !important;
	}


	.add_r {
		flex: 1;
		margin-left: 12rpx;
	}

	.add_r>view {
		display: flex;
	}

	.add_r>view:nth-of-type(2) {
		margin-top: 30rpx;
	}

	.add_r>view text {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #333333;
		width: 480rpx;
	}

	.add_r>view image {
		width: 36rpx;
		height: 36rpx;
		margin-left: 50rpx;
	}

	.add_l {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 8rpx;
	}

	.add_l>view {
		width: 44rpx;
		height: 26rpx;
		background: #D6FFF5;
		border-radius: 4rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #109C7A;
	}

	.add_l>text {
		font-size: 20rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #666666;
	}

	.houtai {
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-top: 10rpx;
		margin-left: 70rpx;
	}



	.shopname {
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		border-top: 1rpx solid #EEEEEE;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		padding-top: 20rpx;
	}

	.tit2 {
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		align-items: center;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
		height: 64rpx;
		align-items: center;
		width: 100%;
		border-bottom: 1rpx solid #EEEEEE;
		box-sizing: border-box;

	}

	.tit2>view>image {
		width: 24rpx;
		height: 24rpx;
		margin-right: 10rpx;
	}

	.tit2>text {
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #F83535;
	}

	.listbg {
		width: 690rpx;
		margin-left: 30rpx;


	}

	.realpay {
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
		display: flex;
		justify-content: flex-end;
		align-items: baseline;
		margin-top: 6rpx;
	}

	.realpay text {
		font-size: 36rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.goodsbtn {
		width: 100%;
		display: flex;
		justify-content: flex-end;
	}

	.goodsbtn>view {
		width: 260rpx;
		height: 60rpx;
		background: linear-gradient(64deg, #2BCCA5, #22B591);
		box-shadow: 0px 4rpx 6rpx 0px rgba(20, 187, 146, 0.4);
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #FFFFFF;
	}

	.listitem {
		width: 100%;
		height: auto;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-top: 20rpx;
		box-sizing: border-box;
	}

	.tit {
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		align-items: center;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.tit text:nth-of-type(2) {
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #F83535;
	}

	.gray {
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;

	}

	.gray1 {
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.price2>view,
	.price2>view text {
		font-size: 26rpx !important;
		font-family: Microsoft YaHei;
		font-weight: 400 !important;
		color: #333333 !important;
	}

	.price2>text {
		margin-top: 4rpx;
		font-size: 22rpx !important;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999 !important;
	}

	.goods2>image {
		width: 140rpx;
		height: 140rpx;
		border-radius: 10rpx;
		/* background: #18BC37; */
		margin-right: 20rpx;

	}

	.one {
		display: flex;
		flex-direction: column;
	}

	.one>text:nth-of-type(1) {
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
		line-height: 36rpx
	}

	.goods {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 12rpx;
	}

	.price {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #F83535;
	}

	.price>view text {
		font-size: 36rpx;

		font-weight: bold;

	}

	.price>text {
		font-size: 22rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.imgbg {
		display: flex;
		align-items: center;
	}

	.imgbg .dian {
		width: 30rpx;
		height: 8rpx;
	}

	.imgbg image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
		margin-right: 10rpx;
	}

	page {
		background: #F5F5F5;
	}

	.box {
		width: 750rpx;
		height: 160rpx;
		overflow: hidden;
		background: linear-gradient(180deg, #109C7A 0%, #109C7A 100%);
		position: relative;
	}

	.box view:nth-of-type(2) {
		width: 100%;
		height: 40rpx;
		border-radius: 20rpx 20rpx 0px 0px;
		position: absolute;
		bottom: 0;
		background: #F5F5F5;
	}

	.timesc {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		margin-top: 36rpx;
		margin-left: 30rpx;
	}

	.timesc image {
		width: 36rpx;
		height: 36rpx;
		margin-left: 2rpx;
	}

	.nomore {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #666666;
		overflow: hidden;
	}

	.nomore image {
		width: 306rpx;
		height: 352rpx;
		margin-top: 90rpx;
	}

	.nomore text:nth-of-type(1) {
		font-size: 34rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #333333;
		margin-bottom: 30rpx;
	}

	.nomore>view {
		font-size: 32rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #FFFFFF;
		width: 300rpx;
		height: 100rpx;
		background: linear-gradient(64deg, #2BCCA5, #22B591);
		box-shadow: 0px 4rpx 6rpx 0px rgba(20, 187, 146, 0.4);
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 130rpx;
	}
</style>
